#version 330

// Fragment shader colors
#ifdef VERT_COLOR
out vec3 fs_Color;
#else
out vec2 fs_txCoord;
#endif

uniform mat4x4 u_lastModel;
uniform mat4x4 u_Model;
uniform mat4x4 u_View;
uniform mat4x4 u_Persp;
uniform mat3x3 u_invTrans;

uniform float u_specularExponent;
uniform float u_frameTime;

in vec3 Position;
in vec3 Normal;
in vec3 Color;
in vec2 txCoord;

out vec3 fs_Normal;
out vec4 fs_Position;
out vec2 fs_SSVelocity;

void main(void) {

#ifdef VERT_COLOR
	fs_Color = Color;
#else
	fs_txCoord = txCoord;
#endif

	fs_Normal = u_invTrans*Normal;
		
	vec4 viewPos = u_View * u_Model * vec4(Position, 1.0f);
	
	vec4 ssPosition = u_Persp * viewPos;
	vec2 lastSSPosition = (u_Persp * u_View * u_lastModel * vec4(Position, 1.0f)).xy;
	
	fs_SSVelocity = (ssPosition.xy - lastSSPosition)/u_frameTime;

	gl_Position = ssPosition;
}